//
//  WBBaseViewController.swift
//  IOS_Mock_WB
//
//  Created by edy on 2024/9/19.
//

import UIKit

class WBBaseViewController: UIViewController {
    
    
    // 自定义导航条
    lazy  var navigationBar=UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
    // 自定义导航项
    lazy var navItem=UINavigationItem()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    override var title: String?{
        didSet{
            navItem.title =  title
            
        }
    }
}


extension WBBaseViewController{
    // 设置页面
    @objc  func setupUI(){
        
        view.addSubview(navigationBar)
        // 使用 Auto Layout 进行布局
        navigationBar.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            navigationBar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            navigationBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            navigationBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            navigationBar.heightAnchor.constraint(equalToConstant: 64)
        ])
        navigationBar.items=[navItem]
        
        // 设置导航栏颜色
        navigationBar.barTintColor=UIColor.white
        // 设置导航栏字体颜色
        navigationBar.titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.darkGray, // 设置字体颜色
            NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16) // 设置字体大小和样式（可选）
        ]

    }
}
